package api

import (
	"github.com/gin-gonic/gin"
)

type resBody struct {
	Code    int         `json:"code" example:"10000"`
	Message string      `json:"message" example:"Success"`
	Data    interface{} `json:"data"`
}

type paginationQuery struct {
	Page     int `form:"page" binding:"omitempty,gte=1"`
	PageSize int `form:"page-size" binding:"omitempty,gte=1"`
}

type list struct {
	Total int64       `json:"total" example:"0"`
	Items interface{} `json:"items"`
}

func Hello(c *gin.Context) {
	resSuc(c, "Hello world")
}

const (
	CodeSuccess = 10000 // Success
	CodeFail    = 20000 // Fail show message

	CodeInvalidUrl   = 20001 // Invalid url
	CodeInvalidBody  = 20002 // Invalid request body
	CodeInvalidForm  = 20003 // Invalid form
	CodeInvalidQuery = 20004 // Invalid query

	CodeNoAuth           = 21000 // No autu
	CodeTokenExpired     = 21001 // Token expired
	CodePermissionDenied = 21002 // Permission denied
	CodeHasLogin         = 21009 // Has login
)

func resSuc(c *gin.Context, data interface{}) {
	c.JSON(200, resBody{
		Code:    CodeSuccess,
		Message: "Success",
		Data:    data,
	})
}

func resFai(c *gin.Context, message string) {
	c.JSON(200, resBody{
		Code:    CodeFail,
		Message: message,
	})
}

func resInvalidBody(c *gin.Context) {
	c.JSON(200, resBody{
		Code:    CodeInvalidBody,
		Message: "Invalid request body",
	})
}

func resInvalidForm(c *gin.Context) {
	c.JSON(200, resBody{
		Code:    CodeInvalidForm,
		Message: "Invalid form",
	})
}

func resInvalidQuery(c *gin.Context) {
	c.JSON(200, resBody{
		Code:    CodeInvalidQuery,
		Message: "Invalid query",
	})
}

func resNoAuth(c *gin.Context) {
	c.JSON(200, resBody{
		Code:    CodeNoAuth,
		Message: "No auth",
	})
}

func resPermissionDenied(c *gin.Context) {
	c.JSON(200, resBody{
		Code:    CodePermissionDenied,
		Message: "Permission denied",
	})
}

func Res(c *gin.Context, code int, message string) {
	c.JSON(200, resBody{
		Code:    code,
		Message: message,
	})
}
